;*****************************************************************************************************
;+
; NAME:
;
;      eWDELETE (Enhanced WDELETE)
;
; PURPOSE:
;
;      This is the enhanced version of the standard IDL WDELETE
;      procedure. It deletes the target active IGL window. See the IDL
;      documentation of the WDELETE command for more details.
;
; CALLING SEQUENCE:
;
;      eWDELETE, windowId
;
; ARGUMENTS:
;
;     WINDOWID:     The identifier of the window. Similar to the
;                   window_index argument of the WDELETE procedure.
;
;                 
; KEYWORD PARAMETERS:
;
;    ALL:           *IGL ADDITION* : Set this keyword to delete all
;                    the currently active IGL windows.
;
; PACKAGE:
;
;    Interactive Graphics Library (IGL)
;
; AUTHORS:
;
;        RAPHAEL SADOUN
;        Graduate Student
;        Institut d'Astrophysique de Paris
;        98 bis boulevard Arago
;        75014 PARIS FRANCE
;        E-mail: raphael.sadoun@gmail.com
;
;
; MODIFICATION HISTORY:
;
;     Written by: Raphael Sadoun, 24 April 2012
;-
;*****************************************************************************************************
PRO eWDELETE, windowID, ALL=all

  COMPILE_OPT idl2, HIDDEN
  ON_ERROR, 2

  ;; Initialize global system variables
  IGL_InitSysVars

  ;; The default is to use the current active window
  IF (n_elements(windowID) EQ 0) THEN windowID = IGL_GetSysVars('currentWindow')

  ;; Get the object reference of the requested window
  windowObjRefs = IGL_GetSysVars('windowObjRefs')

  IF Keyword_Set(all) THEN BEGIN ; Delete all the windows

     FOR i=0, N_Elements(windowObjRefs)-1 DO Obj_Destroy, windowObjRefs[i]

  ENDIF ELSE BEGIN ; Delete only the target window

     ;; Make sure we have a valid identifier
     IF (windowID LT 0) OR (windowID GT 49) THEN Message, 'IGL window identifiers must be between 0 and 49.'
  
     targetWindow = windowObjRefs[windowID]

     ;; If this is a valid window, we make it the current IGL window.
     IF OBJ_ISA_VALID(targetWindow,'IGL_Window') THEN Obj_Destroy, targetWindow $
     ELSE Message, 'Window number '+strtrim(windowID,2)+' out of range or no more windows.'
          
  ENDELSE

END
  

